package com.zoe.tree.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zoe.tree.entity.DeptAncestors;
import com.zoe.tree.service.DeptAncestorsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * @author zbg
 * @date 2023/06/19
 * @description
 */
@RestController
@RequestMapping("dept")
@RequiredArgsConstructor
public class DeptController {

    private final DeptAncestorsService deptAncestorsService;

    // {
    //   "pid": 0,
    //   "name": "部门1"
    // }
    @PostMapping
    public boolean add(@RequestBody DeptAncestors deptAncestors) {
        return deptAncestorsService.save(deptAncestors);
    }

    // {
    //   "id": 7,
    //   "pid": 4,
    //   "nextId": 6
    // }
    @PutMapping("move")
    public boolean move(@RequestBody DeptAncestors deptAncestors) {
        return deptAncestorsService.move(deptAncestors);
    }

    @GetMapping("page")
    public IPage<DeptAncestors> page(Page<DeptAncestors> deptAncestors) {
        return deptAncestorsService.page(deptAncestors);
    }

    @GetMapping("tree")
    public Set<DeptAncestors> tree() {
        return deptAncestorsService.tree();
    }
}
